require "Common/define"
require "Logic/Config"
require "Common/functions"
---@class HeroFavorManager
HeroFavorManager = HeroFavorManager or {};
local this = HeroFavorManager;
this.sortInteractionListData=nil

function HeroFavorManager.init()
    this.initData()
end

function HeroFavorManager.initData()

end

function HeroFavorManager.getInteractionInfo()
    local data=G.dataTable["t_herofavorinteractionlist"]
    local function filter(data)
        if data.f_Hide==1 then
            return true
        else
            return false
        end
    end
    if this.sortInteractionListData==nil then
        this.sortInteractionListData=SortTableData(data,"f_Sort",filter)
    end
    return this.sortInteractionListData,data
end
function HeroFavorManager.GetMaxFavorLevel()
    return 10
end
function HeroFavorManager.getRewardData(heroId)
    local data=G.dataTable["t_herofavorreward"]
    local temp={}
    for i,v in pairs(data)do
        if temp[v.f_RoleID]==nil then
            temp[v.f_RoleID]={}
        end
        temp[v.f_RoleID][v.f_FavorLevel]=v
    end
    if heroId==nil then
        return temp
    else
        return temp[tonumber(heroId)]
    end
end

function HeroFavorManager.checkCanFavorInteract(partnerId,interactId)
    local _,data=logicMgr.HeroFavorManager.getInteractionInfo()
    data=data[tostring(interactId)]
    local heroData=logicMgr.HeroManager.getHeroDatabyPartnerId(partnerId,true)
    if table.isNullOrEmpty(heroData)then
        return false
    end
    local interactData={}
    for i,v in pairs(heroData.interactInfos or {})do
        if v.id==data.f_InteractionId then
            interactData=v
            break
        end
    end
    if table.isNullOrEmpty(interactData)then
        interactData.times=0
    end
    local num=logicMgr.HeroManager.getHeroInteractionNum()
    if data.f_FrequencyType==1 and num<data.f_FrequencyCo then
        if interactData.times<data.f_Frequency then
            return true
        end
    end
    if data.f_FrequencyType==2 and interactData.times<data.f_Frequency then
        return true
    end
    return false
end
return HeroFavorManager